﻿#include "clog.h"

CLog* CLog::m_pLog;
CLog* CLog::getInstance()
{
    if(m_pLog == nullptr)
        m_pLog = new CLog();
    return m_pLog;
}
void CLog::writeLog(const char* msg)
{
    int len = strlen(msg);
    m_file.open(QIODevice::Append);
    QDateTime date = QDateTime::currentDateTime();
    QString current_date =date.toString("yyyy.MM.dd hh:mm:ss");
    current_date += "\n";
    m_file.write(current_date.toStdString().c_str());
    m_file.write(msg,len);
    m_file.close();
}
void CLog::writeLog(QString msg)
{
    m_file.open(QIODevice::Append);
    QDateTime date = QDateTime::currentDateTime();
    QString current_date =date.toString("yyyy.MM.dd hh:mm:ss");
    current_date += "\n";
    m_file.write(current_date.toStdString().c_str());
    m_file.write(msg.toStdString().c_str());
    m_file.close();
}
void CLog::writeLog(std::string msg)
{
     m_file.open(QIODevice::Append);
     QDateTime date = QDateTime::currentDateTime();
     QString current_date =date.toString("yyyy.MM.dd hh:mm:ss");
     current_date += "\n";
     m_file.write(current_date.toStdString().c_str());
     m_file.write(msg.c_str());
     m_file.close();
}
